package com.example.gaoyang.controller;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.example.gaoyang.domain.request.SysElementRequest;
import com.example.gaoyang.domain.vo.SysElementVO;
import com.example.gaoyang.request.Result;
import com.example.gaoyang.service.SysElementService;
import com.example.gaoyang.util.ResultUtil;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@Slf4j
@RestController
@RequestMapping("/sysElement")
public class SysElementController {

    @Resource
    private SysElementService sysElementService;

    @PostMapping("/addSysElement")
    public Result addSysElement(@RequestBody SysElementRequest sysElementRequest) {
        sysElementService.addSysElement(sysElementRequest);
        return ResultUtil.success(String.format("系统元素创建成功,元素名称:[%s]", sysElementRequest.getElementName()));
    }

    @PostMapping("/removeSysElement")
    public Result removeSysElement(@RequestBody SysElementRequest sysElementRequest) {
        sysElementService.removeSysElement(sysElementRequest);
        return ResultUtil.success(String.format("系统元素删除成功,元素名称:[%s]", sysElementRequest.getElementName()));
    }

    @PostMapping("/getSysElementList")
    public Result<List<SysElementVO>> getSysElementList(@RequestBody SysElementRequest sysElementRequest) {
        return ResultUtil.success(sysElementService.getSysElementList(sysElementRequest));
    }

    @PostMapping("/getSysElementPage")
    public Result getSysElementListPage(Page page, @RequestBody SysElementRequest sysElementRequest) {
        return ResultUtil.success(sysElementService.getSysElementPage(page, sysElementRequest));
    }

    @PostMapping("/updateSysElement")
    public Result updateSysElement(@RequestBody SysElementRequest sysElementRequest) {
        sysElementService.updateSysElement(sysElementRequest);
        return ResultUtil.success(String.format("系统元素更新成功,元素名称:[%s]", sysElementRequest.getElementName()));
    }

    @PostMapping("/getAllElementTree")
    public Result<List<SysElementVO>> getAllElementTree() {
        return ResultUtil.success(sysElementService.getAllElementTree());
    }

}
